/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package jollylengkono.skripsi.CollaborativeWorks.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import jollylengkono.skripsi.CollaborativeWorks.form.CollaborativeWorksUpdateForm;
import jollylengkono.skripsi.dao.CollaborativeWorksDao;
import jollylengkono.skripsi.dao.CollaborativeWorksSubjectDao;
import jollylengkono.skripsi.model.CollaborativeWorks;
import jollylengkono.skripsi.model.CollaborativeWorksSubject;
import jollylengkono.skripsi.model.Members;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

/**
 *
 * @author hp02
 */
public class CollaborativeWorksUpdate extends Action {
    private String FORWARD;
    private int STATE;
    
    public CollaborativeWorksUpdate() {
    }

    @Override
    public ActionForward execute(ActionMapping mapping, ActionForm form, 
            HttpServletRequest request, HttpServletResponse response) {
        HttpSession sess = request.getSession(true);
        Members creator = (Members) sess.getAttribute("memberSessObject");
        
        CollaborativeWorksUpdateForm cwForm = (CollaborativeWorksUpdateForm) form;
        CollaborativeWorks cw = new CollaborativeWorks();
        cw.setCreator(creator);
        cw.setDownloaded(cwForm.getDownloaded());
        cw.setFullContent(cwForm.getFullContent());
        cw.setHasDocument(cwForm.getHasDocument());
        cw.setId(cwForm.getId());
        cw.setPublishes(cwForm.getPublishes());
        cw.setShortDescription(cwForm.getShortDescription());
        cw.setStatus(cwForm.getStatus());
        cw.setSubject((CollaborativeWorksSubject) new CollaborativeWorksSubjectDao().read(cwForm.getIdSubject()));
        cw.setTitle(cwForm.getTitle());
        cw.setUpdates(cwForm.getUpdates());
        cw.setWrites(cwForm.getWrites());
        
        this.STATE = new CollaborativeWorksDao().update(cw);
        if(this.STATE==1) {
            this.FORWARD="success";
        } else {
            this.FORWARD="fail";
        }
        return mapping.findForward(FORWARD);
    }

}
